local nadian = fk.CreateSkill{
  name = "lingling__nadian",
}

Fk:loadTranslationTable{
  ["lingling__nadian"] = "纳典",
  [":lingling__nadian"] = "其他角色于弃牌阶段弃置牌时，你可以获得其中所有锦囊牌。当其他角色使用【无懈可击】时，你摸一张牌。",

  ["#lingling__nadian"] = "纳典：你可以获得即将弃置牌中所有锦囊牌",
}

nadian:addEffect(fk.BeforeCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(nadian.name) then
      for _, move in ipairs(data) do
        if move.from and move.from ~= player and move.moveReason == fk.ReasonDiscard and move.skillName == "phase_discard" and move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId)
            if card.type == Card.TypeTrick then
              return true
            end
          end
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = nadian.name,
      prompt = "#lingling__nadian"
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:cancelMove(data, nil, function(move, info)
      if move.from and move.from ~= player and move.moveReason == fk.ReasonDiscard and move.skillName == "phase_discard" and move.toArea == Card.DiscardPile then
        local c = Fk:getCardById(info.cardId)
        return c.type == Card.TypeTrick
      end
      return false
    end)
    -- for _, move in ipairs(data) do
    --   if move.from and move.moveReason == fk.ReasonDiscard and move.skillName == "phase_discard" and move.toArea == Card.DiscardPile then
    --     local infos = {}
    --     for _, info in ipairs(move.moveInfo) do
    --       local c = Fk:getCardById(info.cardId)
    --       if c.type == Card.TypeTrick then
    --         table.insertIfNeed(cards, c)
    --       else
    --         table.insert(infos, info)
    --       end
    --     end
    --     move.moveInfo = infos
    --   end
    -- end
    room:obtainCard(player, cards, true, fk.ReasonJustMove)
  end
})

nadian:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(nadian.name) and data.from and data.from ~= player and data.card and data.card.trueName == "nullification"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, nadian.name)
  end
})

return nadian
